package leetcode.数组;

public class 加一66 {
    public static int[] plusOne(int[] digits) {
        int out = 0;
        digits[digits.length - 1]++;
        for (int i = digits.length - 1; i >= 0; i--) {
            if (digits[i]  >= 10) {
                digits[i] = digits[i] - 10;
                if (i - 1 >= 0)
                    digits[i - 1]++;
                else {
                    out = 1;
                }
            }
        }
        if (out == 1) {
            int[] res = new int[digits.length + 1];
            res[0] = 1;
            for (int i = 1; i < res.length; i++) {
                res[i] = digits[i - 1];
            }
            return res;
        } else
            return digits;

    }

    public static void main(String[] args) {
        int[] res = plusOne(new int[]{9});
        System.out.println(res);
    }
}
